home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / CFMExamples / ModApp / ModuleSources / Button.c next >
Encoding:
C/C++ Source or Header  |  1998-12-03  |  2.8 KB  |  160 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Button.c
  3.  
  4.     Contains:    simple button plug-in.
  5.  
  6.     Written by:    Richard Clark
  7.  
  8.     Copyright:    © 1993-1994, 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.            06/10/98        GAB        compatible with 3.1 interfaces
  13.             8/15/94        BLS        updated to CFM-68K runtime
  14.  
  15. */
  16.  
  17.  
  18. #ifdef THINK_C
  19.     #define ToolStartup main
  20. #endif
  21.  
  22. #ifndef __TYPES__
  23.     #include <Types.h>
  24. #endif
  25.  
  26. #ifndef __QUICKDRAW__
  27.     #include <Quickdraw.h>
  28. #endif
  29.  
  30. #ifndef __CONTROLS__
  31.     #include <Controls.h>
  32. #endif
  33.  
  34. #ifndef __RESOURCES__
  35.     #include <Resources.h>
  36. #endif
  37.  
  38. #ifndef __FILES__
  39.     #include <Files.h>
  40. #endif
  41.  
  42. #ifndef __MIXEDMODE__
  43.     #include <MixedMode.h>
  44. #endif
  45.  
  46. #ifndef __SOUND__
  47.     #include <Sound.h>
  48. #endif
  49.  
  50. #include "ToolAPI.h"
  51. #include "ModApp.h"
  52.  
  53. enum {
  54.     rMyButton = 1001
  55.     };
  56.  
  57. // === Public routines
  58.  
  59. OSErr ToolStartup (WindowPtr wp)
  60. {
  61.     DrawingWindowPeek    aWindow = (DrawingWindowPeek)wp;
  62.     OSErr                err = noErr;
  63.     ControlHandle        myButton;
  64.     short                refNum;
  65.     
  66.     // Don't bother adding anything to the tool window's block, as we don't have any private info
  67.     aWindow->toolRoutines.shutdownProc = ToolShutdown;
  68.     aWindow->toolRoutines.menuAdjustProc = NULL;
  69.     aWindow->toolRoutines.menuDispatchProc = NULL;
  70.     aWindow->toolRoutines.toolIdleProc = NULL;
  71.     aWindow->toolRoutines.toolUpdateProc = ToolUpdate;
  72.     aWindow->toolRoutines.toolClickProc = ToolWindowClick;
  73.     aWindow->toolRoutines.toolWindowMovedProc = NULL;
  74.     aWindow->toolRoutines.toolWindowResizedProc = NULL;
  75.     aWindow->toolRoutines.toolWindowActivateProc = NULL;
  76.  
  77.     // Add our button
  78.     SetPort(wp);
  79.     EraseRect(&wp->portRect);
  80.     refNum = FSpOpenResFile(&aWindow->toolSpec, fsCurPerm);
  81.     err = ResError();
  82.     if (err) goto error;
  83.     myButton = GetNewControl(rMyButton, wp);
  84.     CloseResFile(refNum);
  85.  
  86. error:
  87.     return err;
  88. }
  89.  
  90.  
  91. void ToolShutdown (WindowPtr wp)
  92. {
  93.     DrawingWindowPeek    aWindow = (DrawingWindowPeek)wp;
  94.  
  95.     DisposeControl((ControlHandle) ((WindowPeek)wp)->controlList);
  96. }
  97.  
  98.  
  99. void ToolMenuAdjust (WindowPtr wp)
  100. {
  101.     #pragma unused(wp)
  102. }
  103.  
  104.  
  105. void ToolMenuDispatch (WindowPtr wp, short menuID, short itemID)
  106. {
  107.     #pragma unused(wp, menuID, itemID)
  108. }
  109.  
  110.  
  111. void ToolIdle (WindowPtr wp)
  112. {
  113.     #pragma unused(wp)
  114. }
  115.  
  116.  
  117. void ToolUpdate (WindowPtr wp)
  118. {
  119.     DrawControls(wp);    
  120. }
  121.  
  122.  
  123. void ToolWindowClick(WindowPtr wp, EventRecord *theEvent)
  124. {
  125.     Point            globalPt = theEvent->where;
  126.     Point            localPt;
  127.     ControlHandle    theControl;
  128.     int16            partCode;
  129.     
  130.     SetPort(wp);
  131.     localPt = globalPt; GlobalToLocal(&localPt);
  132.     partCode = FindControl(localPt, wp, &theControl);
  133.     if (partCode) {
  134.         partCode = TrackControl(theControl, localPt, NULL);
  135.         if (partCode) {
  136.             SysBeep(3);
  137.             SysBeep(3);
  138.             SysBeep(3);
  139.         }
  140.     }
  141. }
  142.  
  143.  
  144. void ToolWindowMoved(WindowPtr wp)
  145. {
  146.     #pragma unused(wp)
  147. }
  148.  
  149.  
  150. void ToolWindowResized(WindowPtr wp)
  151. {
  152.     #pragma unused(wp)
  153. }
  154.  
  155.  
  156. void ToolWindowActivate(WindowPtr wp, Boolean activeFlag)
  157. {
  158.     #pragma unused(wp, activeFlag)
  159. }
  160.